import {http} from "@/utils/http/axios";
const $dialog = window['$dialog']
export const downloadFile = (url, fileName?) => {
    console.log(url);
    const strArr = url.split(/\//g);
    fileName = fileName || strArr[strArr.length - 1];
    http.request({
        url: `https://resourcelib-test.oss-cn-hangzhou.aliyuncs.com/${url}`,
        method: 'GET',
        responseType:'blob',
    },{isTransformResponse:false}).then(result => {
        const blob = new Blob([result], {type: 'application/octet-stream'});
        // if (window.navigator.msSaveOrOpenBlob) {
        //     window.navigator.msSaveOrOpenBlob(blob, fileName);
        // } else {
            const a = document.createElement('a');
            a.download = fileName;
            a.href = URL.createObjectURL(blob);
            document.body.appendChild(a);
            a.click();
            document.body.removeChild(a);
        // }
    }, () => {
        $dialog.warning({
            title:'提示',content:'文件下载失败'
        })
    })
};
